package c03.locksupport;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.LockSupport;

import static util.Sleeper.sleep;

@Slf4j(topic = "c.LockSupportParkTest3")
public class LockSupportParkTest3 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                log.debug("before park t1 interrupted: {}", Thread.currentThread().isInterrupted());
                log.debug("park ......");
                LockSupport.park(); // 程序在此等待
                boolean interrupted = Thread.interrupted();  // 清除打断标记
                log.debug("after Thread.interrupted() t1 interrupted: {}", interrupted);
            }
        });
        t1.start();
        sleep(1);
        // 给t1线程发送中断指令
        t1.interrupt();
    }
}
